//
// Created by liushuai on 2020/4/1.
//
#include "rob.h"
int rob(vector<int>& nums){
    int size = nums.size();
    int result = 0;
    if(size==0)
        return 0;
    else if(size == 1)
        return nums.at(0);
    else if(size == 2)
        return max(nums.at(0),nums.at(1));
    else{
        int start = 2;
        int lower = nums.at(0);
        int upper = max(nums.at(0),nums.at(1));
        while (start<size){
            result = max(lower+nums.at(start),upper);
            lower = upper;
            upper = result;
            start++;
        }
        return result;
    }
}
